home *** CD-ROM | disk | FTP | other *** search
Text File | 1990-03-23 | 1.6 KB | 59 lines | [TEXT/GEOL] |
- Item 7256363 19-March-90 10:23PST
-
- From: NAUTIL France - Dev, Nautil Info Lyon,IDV
-
- To: CPLUS.APPLE$ C++ Interest List--Apple Employees
- CPLUS.DEV$ C++ Interest List--Developers
-
- Sub: THzBlock class
-
- Hi,
- Do you remember my problems with allocation ambiguity?!
-
- Well, reading "C++ Reference manual" again and again, I discovered some
- solution: the 'placement' syntax can supply additional arguments to operator
- new. So I now define a base class wich can to be allocated with any Memory
- Manager call :
-
- #include <StdDef.h>
- #include <Memory.h>
- // If using MacApp permanent allocation :
- #include <UMemory.h>
-
- typedef pascal Ptr (*new_p)(Size);
-
- class THzBlock {
- public:
- void* operator new(size_t size, new_p mmgrNew) { return (*mmgrNew)(size); }
- void operator delete(void* p);
- };
-
-
- void THzBlock::operator delete(void* p)
- // Current zone is set to the zone where the block is located.
- // (see IM II-26 warning).
- // ??? But, is it really necessary ???
- {
- THz oldZone = GetZone();
- SetZone(PtrZone((Ptr)p));
- DisposPtr((Ptr)p);
- SetZone(oldZone);
- }
-
-
- void sample(void)
- {
- THzBlock* currentHeapBlock = new (NewPtr) THzBlock;
- THzBlock* systemHeapBlock = new (NewPtrSys) THzBlock;
- THzBlock* clearBlock = new (NewPtrClear) THzBlock;
- THzBlock* sysClearBlock = new (NewPtrSysClear) THzBlock;
- THzBlock* permMacAppBlock = new (NewPermPtr) THzBlock;
- }
-
-
- I hope this class can help every one interested in using direct Memory Manager
- calls to allocate C++ objects.
-
- Etienne Vautherin
-
-